<template>
	<div v-loading="loading">
		<group>
			<x-input title="手机：" disabled v-model="form.phone"></x-input>
			<x-input title="姓名：" disabled v-model="form.vip_name"></x-input>
			<x-input title="性别：" disabled v-if="form.sex==1" value="女"></x-input>
			<x-input title="性别：" disabled v-else-if="form.sex==0" value="男"></x-input>
			<x-input title="性别：" disabled v-else value="保密"></x-input>
			<x-input title="生日：" disabled v-model="form.birth_date"></x-input>
		</group>
		<group>
			<x-input title="身高：" placeholder="请输入身高" v-model="form.toinfo.height">
				<span slot="right">cm</span>
			</x-input>
			<x-input title="体重：" placeholder="请输入体重" v-model="form.toinfo.weight"></x-input>
		</group>
		<group>
			<x-address title="地　　址：" placeholder="请选择地址" :list="addressData" @on-shadow-change="addresschange" v-model="changeaddres"></x-address>
			<x-textarea title="详细地址：" placeholder="请输入详细地址" v-model="form.toinfo.address"></x-textarea>
		</group>
		<group>
			<x-input title="职业：" placeholder="请输入职业" v-model="form.toinfo.vip_info_zhiye"></x-input>
			<x-input title="爱好：" placeholder="请输入爱好" v-model="form.toinfo.vip_info_aihao"></x-input>
		</group>
		<box gap="20px 10px">
			<x-button type="primary" :show-loading="submiloading" @click.native="submit">保存</x-button>
		</box>
    <back></back>
	</div>
</template>

<script>
// import {regionData as addressData1} from 'element-china-area-data'
import {ChinaAddressV4Data as addressData} from 'vux'
import back from '@/components/back/backPrev';
	export default {
		directives: {

		},
		components:{
      back
		},
		data(){
			return {
				changeaddres : [],
				addressData,
				form : {
					toinfo : {}
				},
				loading : false,
				submiloading : false
			}
		},
		methods : {
			addresschange(ids, names){
				this.form.toinfo.province_code = ids[0]
				this.form.toinfo.city_code = ids[1]
				this.form.toinfo.area_code = ids[2]
				this.form.toinfo.regions_name = names.join('-')
			},
			initdata(){
				this.loading = true;
				this.$http.member.get('vipInfo/getVipInfo').then(res => {
					if(!res.data.code){
					  // console.log(res.data) county_code
						this.form = res.data.data;
						this.changeaddres = [this.form.toinfo.province_code+'',this.form.toinfo.city_code+'',this.form.toinfo.county_code+'']
            // console.log(this.changeaddres)
					}
					this.loading = false;
				})
          .catch(err => {
            this.$message({
              message: '登陆过期，请重新登陆！',
              type: 'error'
            });
            localStorage.removeItem('user');
            localStorage.removeItem('company');
            localStorage.removeItem('api_token');
            localStorage.removeItem('refresh_token');
            location.reload()
          })
			},
			submit(){
				this.submiloading = true;
				this.$http.member.put('vipInfo/updateVipInfo',{
					nickname : this.form.toinfo.nickname,
					qq_number : this.form.toinfo.qq_number,
					height : this.form.toinfo.height,
					weight : this.form.toinfo.weight,
					province_code : this.form.toinfo.province_code,
					city_code : this.form.toinfo.city_code,
					county_code : this.form.toinfo.area_code,
					address : this.form.toinfo.address,
          vip_info_zhiye:this.form.toinfo.vip_info_zhiye,
          vip_info_aihao:this.form.toinfo.vip_info_aihao
				}).then(res => {
					if(!res.data.code){
						this.$message.success('修改成功')
						this.initdata();
					}else{
						this.$message.error('修改失败,'+res.data.message)
					}
					this.submiloading = false;
				})
			}
		},
		computed : {
		},
		created(){
			this.initdata();

		},
		watch : {

		}
	}
</script>
